<?php
class cats_init extends PHPUnit_Framework_TestCase{

    public function setUp()
    {
		$this->object = kernel::single('tbdata_api_tbapi');
		$this->cat_model = app::get('tbdata')->model('cats');
    }
	public function get_cats($cid){
		$params['parent_cid'] = $cid;
		$params['method'] = 'taobao.itemcats.get';
		$params['fields'] = 'cid,parent_cid,name,is_parent,status,sort_order';
		$cats = $this->object->get_data($params);
		if($cats['itemcats_get_response']['item_cats']['item_cat']){
			$cat_array = $cats['itemcats_get_response']['item_cats']['item_cat'];
			foreach($cat_array as $cat){
				$this->cat_model->save($cat);
				unset($cat['id']);
				if($cat['is_parent']){
					$this->get_cats($cat['cid']);
				}
			}
		}
	}
    public function testGetcat(){

	
		$cats = $this->get_cats(50008164);
		
		

		print_r($cats);exit;

		
		/*
		$params['method'] = 'taobao.itemprops.get';
		$params['cid'] = 1403;
		$params['fields'] = 'pid,name,must,multi,prop_values,is_key_prop,is_sale_prop,is_item_prop,is_enum_prop';
		$a = $object->get_data($params);
		print_r($a);exit;
		
		*/
		/*
		$params['method'] = 'taobao.itemprops.get';
		$params['cid'] = 1403;
		$params['child_path'] = '20000:10752';
		$params['fields'] = 'pid,name,must,multi,prop_values,is_key_prop,is_sale_prop,is_item_prop';
		$a = $object->get_data($params);
		print_r($a);exit;
		*/
		
		/*
		$params['method'] = 'taobao.product.get';
		$params['cid'] = 1403;
		$params['child_path'] = '20000:10752;20225:23570';
		#$params['pid'] = '20000';
		#$params['parent_pid'] = '94544809';
		$params['fields'] = 'pid,name,must,multi,prop_values,is_key_prop,is_sale_prop,is_item_prop';
		$a = $object->get_data($params);
		print_r($a);exit;
		*/

		
		$params['method'] = 'taobao.products.search';
		$params['cid'] = 1403;
		$params['fields'] = 'product_id,name,pic_url,cid,props,binds_str,price,tsc';
		$a = $object->get_data($params);
		print_r($a);exit;
		/*
		$params['method'] = 'taobao.product.get';
		$params['cid'] = 1403;
		$params['product_id'] = 132096064;
		$params['fields'] = 'cat_name,props,binds,name,sale_props,price,desc,product_imgs,pic_url,pic_path';
		$a = $object->get_data($params);
		print_r($a);*/
		

	}
}
